package com.marvels.financial.utils;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

import com.marvels.common.utils.MarvelsLogUtil;
import com.marvels.common.utils.ServerProperties;
import com.marvels.financial.pay.ybpay.Api;

public class ZipUtils {

	/**
	 * 解压zip文件
	 * @param file
	 */
	public static boolean unzipFile(String sourceFilePath,String targetFilePath)throws Exception{
		File file = new File(sourceFilePath);
		if(!file.exists()){
			return false;
		}
		long startTime=System.currentTimeMillis();  
		ZipInputStream zipStream=null;
		BufferedInputStream bufferStream=null;
		FileOutputStream out = null;
		BufferedOutputStream bOut = null;
        try {  
        	zipStream=new ZipInputStream(new FileInputStream(file));//输入源zip路径  
        	bufferStream=new BufferedInputStream(zipStream);  
            File txtfile=null;  
            ZipEntry entry;  
  
            while((entry = zipStream.getNextEntry())!=null && !entry.isDirectory()){  
                txtfile = new File(targetFilePath);
                if(!txtfile.getParentFile().exists()){
                	txtfile.getParentFile().mkdirs();
                }
 
                out=new FileOutputStream(txtfile);  
                bOut=new BufferedOutputStream(out);  
                int b;  
                while((b=bufferStream.read())!=-1){  
                	bOut.write(b);  
                }  
                 
            }  
            bufferStream.close();  
            zipStream.close();  
              
        } catch (Exception e) {  
        	MarvelsLogUtil.getInstance().error(e+"",e);
        	file.deleteOnExit();
            e.printStackTrace();  
        }finally{
        	bOut.close();  
            out.close();
            bOut.close();  
            out.close(); 
        }  
        long endTime=System.currentTimeMillis();  
        System.out.println("耗费时间： "+(endTime-startTime)+" ms");  
        return true;
	}
	
	
	public static void main(String[] args) {
		String merchantNo  = ServerProperties.getValue("D:/workSpace_sell/marvels-core-v2-simple-1.0.0/marvels-core-financial/src/main/resources/test", "common.properties", "yb.merchantno.withhold");
		String appKey = "SQKK"+merchantNo;
		Map<String,String> map=new HashMap<String,String>();
	    /*map.put("merchantno", merchantNo);
	    map.put("requestno", "201810302239435537bb2dyb");
	    map.put("paymentyborderid", "PONC50e06fc8f63144a1ac56d5bb2c5328f3");
	    map.put("amount", "100.00");
	    map.put("callbackurl", "");
	    map.put("requesttime", "2018-10-30 22:42:45");
	    map.put("remark", "");
		Map<String, Object> returnMap = Api.ybPost(map, "/rest/v1.0/paperorder/api/refund/request",appKey);
		System.out.println(returnMap.toString());*/
		
		map.put("merchantno", merchantNo);
	    map.put("requestno", "2018103022460134562489yb");
	    map.put("paymentyborderid", "PONCfdf562619f154684939222e218e76973");
	    map.put("amount", "100.00");
	    map.put("callbackurl", "");
	    map.put("requesttime", "2018-10-30 22:46:05");
	    map.put("remark", "");
		Map<String, Object> returnMap = Api.ybPost(map, "/rest/v1.0/paperorder/api/refund/request",appKey);
		System.out.println(returnMap.toString());
	}
}
